//
//  HomeCollectionReusableViewHeaderView.m
//  TravelFollowYourHeart
//
//  Created by 鲁万玺 on 2017/12/8.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "HomeCollectionReusableViewHeaderView.h"

#define btnTag 10001
#define JieShaoTag 100001

@interface HomeCollectionReusableViewHeaderView()<SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *tongZhiLabel;

@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIButton *btn0;
@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
@property (weak, nonatomic) IBOutlet UIButton *btn3;
@property (weak, nonatomic) IBOutlet UIButton *btn4;
@property (weak, nonatomic) IBOutlet UIButton *btn5;
@property (weak, nonatomic) IBOutlet UIButton *btn6;

@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn0;
@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn1;
@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn2;
@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn3;
@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn4;
@property (weak, nonatomic) IBOutlet UIButton *jieshaoBtn5;


@end

@implementation HomeCollectionReusableViewHeaderView(Networking)

- (void)getslideShow
{
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/slideShow") andParas:@{} andTransferGottenData:^(id obj, NSError *error) {
        if (error)
        {
            
        }
        else
        {
            if([obj[@"code"] integerValue] == 100000)
            {
                NSMutableArray *arr = [NSMutableArray array];
                for (NSDictionary *dic in obj[@"data"])
                {
                    [arr addObject:dic[@"pic"]];
                }
                self.cycleScrollView.imageURLStringsGroup = arr;
            }
        }
    }];
    
}

- (void)getTZ
{
    WS(ws)
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/notice") andParas:@{} andTransferGottenData:^(id obj, NSError *error) {
        if (error)
        {
            
        }
        else
        {
            if([obj[@"code"] integerValue] == 100000)
            {
                NSArray *arr = obj[@"data"];
                ws.tongZhiLabel.text = [arr firstObject];
            }
        }
    }];
}



@end

@implementation HomeCollectionReusableViewHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
//    [self getRollPlayPic];
    // 网络加载 --- 创建带标题的图片轮播器
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.bgView.height) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    self.cycleScrollView.currentPageDotColor = [UIColor whiteColor];
    self.cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
        NSLog(@">>>>>  %ld", (long)index);
    };
    [self.bgView addSubview:self.cycleScrollView];
    
    self.btn0.tag = btnTag+0;
    self.btn1.tag = btnTag+1;
    self.btn2.tag = btnTag+2;
    self.btn3.tag = btnTag+3;
    self.btn4.tag = btnTag+4;
    self.btn5.tag = btnTag+5;
    self.btn6.tag = btnTag+6;
    
    [self.btn0 setCornerRadius:25.0/2];
    [self.btn1 setCornerRadius:25.0/2];
    [self.btn2 setCornerRadius:25.0/2];
    [self.btn3 setCornerRadius:25.0/2];
    [self.btn4 setCornerRadius:25.0/2];
    [self.btn5 setCornerRadius:25.0/2];
    [self.btn6 setCornerRadius:25.0/2];
    
    self.jieshaoBtn0.tag = JieShaoTag+0;
    self.jieshaoBtn1.tag = JieShaoTag+1;
    self.jieshaoBtn2.tag = JieShaoTag+2;
    self.jieshaoBtn3.tag = JieShaoTag+3;
    self.jieshaoBtn4.tag = JieShaoTag+4;
    self.jieshaoBtn5.tag = JieShaoTag+5;
    
    [self getslideShow];
    [self getTZ];
}

#pragma mark - Event

- (IBAction)clickMore:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(moreClick)])
    {
        [self.delegate moreClick];
    }
}
//——热门推荐——下的点击事件
- (IBAction)chooseTJ:(UIButton *)sender
{
    if (sender.selected || ![self.delegate respondsToSelector:@selector(rmtjClick:)])
    {
        return;
    }
    for (int i = btnTag; i<=btnTag+6; i++)
    {
        UIButton *button = [self viewWithTag:i];
        if (button == sender)
        {
            button.selected = YES;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor themeColor];
        }
        else
        {
            button.selected = NO;
            [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1];
        }
        
    }
    [self.delegate rmtjClick:sender.tag - btnTag];
}

//乡思乡游等栏目点击事件
- (IBAction)jieshaoClick:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(jieshaoClick:)])
    {
        [self.delegate jieshaoClick:sender.tag - JieShaoTag];
    }
}


@end
